<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function setCookie(name,value,iDay){//设置cookie的名字、值、截止时间
            var oDate=new Date();
            oDate.setDate(oDate.getDate()+iDay);
           document.cookie=name+'='+value+';expires='+oDate;//给cookie添加内容

        }

        function getCookie(name){
//            先将document.cookie做字符串分割,第一遍用；分割，第二遍用=分割
           var arr=document.cookie.split(';');
           for(var i=0;i<arr.length;i++){
               var arr2=arr[i].split('=');
//               arr2[0];//name
//               arr2[1];//value
               if(arr2[0]==name){
                   return arr2[1];
               }
           }
           return '';
        }

        setCookie('userName','xiongcheng',100);
        setCookie('password','123456',100);

        alert(getCookie('userName'));
        alert(getCookie('password'));

        alert(document.cookie);
    </script>
</head>
<body>

</body>
</html>